-- kill_bonus2
-- created by cheny3
-- 击杀敌人奖励

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return;
        end

        local pos = who:getPos();
        local grid = DungeonM.getGridByPos(pos);
        local element = grid.element;
        local args = DungeonM.queryElement(element, "args") or {};
        local bonus = args["kill_bonus2"];
        if not bonus then
            return;
        end

        if type(bonus) == "table" and #bonus > 0 then
            -- 配置了固定掉落
            bonus = bonus;
        elseif type(bonus) == "string" then
            -- 配置了公式计算
            bonus = FormulaM.invoke(bonus, ME.user);
        end

        if type(bonus) ~= "table" or #bonus < 0 then
            -- 没奖励
            return;
        end

        if type(bonus[1]) == "number" then
            -- 转换一下格式
            bonus = { bonus };
        end

        for _, perBonus in pairs(bonus) do
            BonusM.doBonus(perBonus, "kill_bonus2");
        end

        -- 抛出事件
        -- 抛出通用建筑奖励事件
        EventMgr.fire(event.COMM_BUILDING_BONUS, {
            ["pos"]   = pos,
            ["type"]  = GRID_TYPE_MONSTER,
            ["bonus"] = { ["bonus"] = bonus },
            ["remainGrid"] = true,
        });
    end,

    record = function(target, prop, path)
        return false;
    end
};
